<html>
<head><meta charset="utf-8"><title>confused about elided lifetime in path error · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html">confused about elided lifetime in path error</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224424590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/confused%20about%20elided%20lifetime%20in%20path%20error/near/224424590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html#224424590">(Jan 29 2021 at 02:36)</a>:</h4>
<p>I'm working on a change in rustdoc, but I'm running into a weird case of the "elided lifetime in path" lint. I have this code:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">fmt</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">comma_sep</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">fmt</span>::<span class="n">Display</span><span class="o">&gt;</span><span class="p">(</span><span class="n">items</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">fmt</span>::<span class="n">Display</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">struct</span> <span class="nc">CommaSep</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">fmt</span>::<span class="n">Display</span><span class="o">&gt;</span><span class="p">(</span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">fmt</span>::<span class="n">Display</span><span class="o">&gt;</span><span class="w"> </span><span class="n">fmt</span>::<span class="n">Display</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">CommaSep</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">fn</span> <span class="nf">fmt</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">f</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">fmt</span>::<span class="n">Formatter</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">fmt</span>::<span class="nb">Result</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">item</span><span class="p">)</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="mf">0.</span><span class="n">iter</span><span class="p">().</span><span class="n">enumerate</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="k">if</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                    </span><span class="fm">write!</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="w"> </span><span class="s">", "</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">                </span><span class="p">}</span><span class="w"></span>
<span class="w">                </span><span class="n">fmt</span>::<span class="n">Display</span>::<span class="n">fmt</span><span class="p">(</span><span class="o">&amp;</span><span class="n">item</span><span class="p">,</span><span class="w"> </span><span class="n">f</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">            </span><span class="nb">Ok</span><span class="p">(())</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="n">CommaSep</span><span class="p">(</span><span class="n">items</span><span class="p">.</span><span class="n">collect</span><span class="p">())</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>which produces this error:</p>
<div class="codehilite"><pre><span></span><code>error: hidden lifetime parameters in types are deprecated
   --&gt; src/librustdoc/html/format.rs:146:31
    |
146 |         fn fmt(&amp;self, f: &amp;mut fmt::Formatter) -&gt; fmt::Result {
    |                               ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `&lt;&#39;_&gt;`
    |
    = note: `-D elided-lifetimes-in-paths` implied by `-D warnings`

error: aborting due to previous error

error: could not compile `rustdoc`
</code></pre></div>
<p>yet if I copy-paste this code into a playground, it compiles fine!</p>
<p>So I'm quite confused about what's wrong.</p>



<a name="224424597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/confused%20about%20elided%20lifetime%20in%20path%20error/near/224424597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html#224424597">(Jan 29 2021 at 02:36)</a>:</h4>
<p>Any help much appreciated! :)</p>



<a name="224425099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/confused%20about%20elided%20lifetime%20in%20path%20error/near/224425099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html#224425099">(Jan 29 2021 at 02:46)</a>:</h4>
<p>Steps to reproduce:</p>
<ol>
<li>
<p>Checkout commit <code>bf193d69fe48f4ec3cac57ab7abb4e9f2a291661</code> (the current tip of <code>master</code>)</p>
</li>
<li>
<p>Apply this patch:</p>
</li>
</ol>
<div class="codehilite" data-code-language="Diff"><pre><span></span><code><span class="gh">diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs</span>
<span class="gh">index 01915c33a07..1ee30c18a4e 100644</span>
<span class="gd">--- a/src/librustdoc/html/format.rs</span>
<span class="gi">+++ b/src/librustdoc/html/format.rs</span>
<span class="gu">@@ -141,15 +141,20 @@ impl Buffer {</span>
}

fn comma_sep&lt;T: fmt::Display&gt;(items: impl Iterator&lt;Item = T&gt;) -&gt; impl fmt::Display {
<span class="gd">-    display_fn(move |f| {</span>
<span class="gd">-        for (i, item) in items.enumerate() {</span>
<span class="gd">-            if i != 0 {</span>
<span class="gd">-                write!(f, ", ")?;</span>
<span class="gi">+    struct CommaSep&lt;T: fmt::Display&gt;(Vec&lt;T&gt;);</span>
<span class="gi">+    impl&lt;T: fmt::Display&gt; fmt::Display for CommaSep&lt;T&gt; {</span>
<span class="gi">+        fn fmt(&amp;self, f: &amp;mut fmt::Formatter) -&gt; fmt::Result {</span>
<span class="gi">+            for (i, item) in self.0.iter().enumerate() {</span>
<span class="gi">+                if i != 0 {</span>
<span class="gi">+                    write!(f, ", ")?;</span>
<span class="gi">+                }</span>
<span class="gi">+                fmt::Display::fmt(&amp;item, f)?;</span>
            }
<span class="gd">-            fmt::Display::fmt(&amp;item, f)?;</span>
<span class="gi">+            Ok(())</span>
        }
<span class="gd">-        Ok(())</span>
<span class="gd">-    })</span>
<span class="gi">+    }</span>
<span class="gi">+</span>
<span class="gi">+    CommaSep(items.collect())</span>
}

crate fn print_generic_bounds&lt;'a&gt;(
</code></pre></div>
<ol start="3">
<li>Run <code>./x.py check</code></li>
</ol>



<a name="224425546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/confused%20about%20elided%20lifetime%20in%20path%20error/near/224425546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html#224425546">(Jan 29 2021 at 02:57)</a>:</h4>
<p>Seems to come from <code>-Wrust_2018_idioms</code> (and <code>-D warnings</code>) being passed to rustc.</p>



<a name="224425625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/confused%20about%20elided%20lifetime%20in%20path%20error/near/224425625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html#224425625">(Jan 29 2021 at 02:59)</a>:</h4>
<p>Perhaps this will help -- <a href="https://users.rust-lang.org/t/what-is-the-elided-lifetimes-in-paths-lint-for/28005">https://users.rust-lang.org/t/what-is-the-elided-lifetimes-in-paths-lint-for/28005</a></p>



<a name="224427109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/confused%20about%20elided%20lifetime%20in%20path%20error/near/224427109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html#224427109">(Jan 29 2021 at 03:30)</a>:</h4>
<p>Huh, I thought that lint was warn-by-default. I guess not. Thanks!</p>



<a name="224679144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/confused%20about%20elided%20lifetime%20in%20path%20error/near/224679144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html#224679144">(Feb 01 2021 at 02:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/confused.20about.20elided.20lifetime.20in.20path.20error/near/224427109">said</a>:</p>
<blockquote>
<p>Huh, I thought that lint was warn-by-default. I guess not. Thanks!</p>
</blockquote>
<p>you can set <code>deny-warnings = false</code> in config.toml</p>



<a name="224679153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/confused%20about%20elided%20lifetime%20in%20path%20error/near/224679153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html#224679153">(Feb 01 2021 at 02:16)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/77492">https://github.com/rust-lang/rust/pull/77492</a></p>



<a name="224684129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/confused%20about%20elided%20lifetime%20in%20path%20error/near/224684129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/confused.20about.20elided.20lifetime.20in.20path.20error.html#224684129">(Feb 01 2021 at 04:12)</a>:</h4>
<p>Well, I could, but then CI would fail. The issue was I didn't realize this lint was enabled by x.py and didn't understand why I was getting in rustdoc but not in the Playground.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>